﻿using System;
using Silver3D.Math;

namespace Silver3D.Graphics
{
    public class OrthographicCamera : Camera
    {
        double left = -1.0, right = 1.0, bottom = -1.0, top = 1.0;

        public double Left
        {
            get { return left; }
            set { left = value; IsProjectionDirty = true; }
        }

        public double Right
        {
            get { return right; }
            set { right = value; IsProjectionDirty = true; }
        }

        public double Bottom
        {
            get { return bottom; }
            set { bottom = value; IsProjectionDirty = true; }
        }

        public double Top
        {
            get { return top; }
            set { top = value; IsProjectionDirty = true; }
        }

        public OrthographicCamera(Scene scene, string id)
            : base(scene, id)
        {
        }

        protected override void UpdateProjection()
        {
            projection = new Matrix44(
                2.0 / (right - left), 0.0, 0.0, -(right + left) / (right - left),
                0.0, 2.0 / (top - bottom), 0.0, -(top + bottom) / (top - bottom),
                0.0, 0.0, -2.0 / (ZFar - ZNear), -(ZFar + ZNear) / (ZFar - ZNear),
                0.0, 0.0, 0.0, 1.0);
        }
    }
}
